﻿

CREATE VIEW [dbo].[fares_FisaPartenerului]
AS
SELECT     dbo.TipDocument.Denumire +'(' + dbo.TipDocument.TipOperatie + ')'  AS TipDocument, dbo.Documente.NrDoc, dbo.Documente.DataDoc, dbo.Documente.Total AS Obligatie, 0 AS Plata, NULL AS DataExtras, 
                      dbo.Documente.IDDocument, dbo.Documente.CodUnitate, dbo.Documente.IDPartener, p.Denumire AS denPartener, dbo.TipDocument.IDTipDocument
FROM         dbo.Documente INNER JOIN
                      dbo.TipDocument ON dbo.Documente.IDTipDocument = dbo.TipDocument.IDTipDocument JOIN
                      Parteneri p ON dbo.Documente.IDPartener = p.IDPartener
UNION
SELECT     b.Denumire AS TipDocument, Numar AS NrDoc, Data AS DataDoc, 0 AS Obligatie, ValoareTotala AS Plata, a.Dataextras, NULL, a.codUnitate, a.IDPartener, 
                      p.Denumire AS denPartener, b.IDTipPlata + 1000 AS IDTipDocument
FROM         DocumentePlata a JOIN
                      TipDocumentPlata b ON a.IDTipPlata = b.IDTipPlata JOIN
                      Parteneri p ON a.IDPartener = p.IDPartener